<!--
Copyright © 2017, Che-Wei Hsu <cwxhsu@gmail.com>
This file is part of the MintCM.
Some rights reserved. See README.
-->

<html>

<head>

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery_main.js"></script>
<script type="text/javascript" src="json3.js"></script>
<script type="text/javascript" src="mcm_jslib_api.js"></script>
<script type="text/javascript" src="mcm_jslib_data_info_auto.js"></script>
<script type="text/javascript" src="web_app_0304_script.js"></script>
<link rel="stylesheet" href="web_app_0304_style.css">

<script type="text/javascript">
function body_init()
{
    var self_jslib, req_cmd, rep_ret, mcm_dv, data_array, i, j, tmp_html = "";


    // 指定要讀出的資料.
    req_cmd = "&get.device" +
              "&get.device.system" +
              "&get.device.vap.*" +
              "&get.device.vap.*.extra" +
              "&get.device.vap.*.station.*" +
              "&get.device.limit.*";

    // 送出讀出資料請求.
    self_jslib = new mcm_jslib_lib_t();
    self_jslib.socket_path = "@mintcm";
    self_jslib.session_permission = mcm_session_permission.ro;
    self_jslib.session_stack_size = 0;
    self_jslib.request_command = req_cmd;
    self_jslib.data_format = mcm_data_format.all_default;
    self_jslib.other_query = "";
    rep_ret = mcm_jslib_obtain_config(self_jslib);
    if(rep_ret.rep_code < mcm_return_code.pass)
    {
        alert("call mcm_jslib_obtain_config() fail" +
              "[" + rep_ret.rep_code + "]");
        mcm_jslib_run_script(rep_ret.rep_data);
        return;
    }
    // 處理資料格式.
    mcm_dv = JSON.parse(rep_ret.rep_data);

    // 顯示資料筆數.
    data_array = new Array(2);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[0].push("device.vap.*");
    data_array[1].push(mcm_dv.device.vap.length);
    for(i = 0; i < mcm_dv.device.vap.length; i++)
    {
        data_array[0].push("device.vap.@" + (i + 1) + ".station.*");
        data_array[1].push(mcm_dv.device.vap[i].station.length);
    }
    data_array[0].push("device.limit.*");
    data_array[1].push(mcm_dv.device.limit.length);
    tmp_html += "[count]";
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    tmp_html += "<br>[get]";

    // 顯示 device
    data_array = new Array(3);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[0].push("");
    data_array[1].push("descript");
    data_array[2].push("serial_number");
    data_array[0].push("device");
    data_array[1].push(mcm_jslib_convert_html_str(mcm_dv.device.descript));
    data_array[2].push(mcm_dv.device.serial_number);
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    // 顯示 device.system
    data_array = new Array(5);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[3] = new Array();
    data_array[4] = new Array();
    data_array[0].push("");
    data_array[1].push("date");
    data_array[2].push("ip_addr");
    data_array[3].push("uptime");
    data_array[4].push("loading");
    data_array[0].push("device.system");
    data_array[1].push(mcm_jslib_convert_html_str(mcm_dv.device.system.date));
    data_array[2].push(mcm_jslib_convert_html_str(mcm_dv.device.system.ip_addr));
    data_array[3].push(mcm_dv.device.system.uptime);
    data_array[4].push(mcm_dv.device.system.loading);
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    // 顯示 device.vap.*
    data_array = new Array(4);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[3] = new Array();
    data_array[0].push("");
    data_array[1].push("ekey");
    data_array[2].push("ssid");
    data_array[3].push("channel");
    for(i = 0; i < mcm_dv.device.vap.length; i++)
    {
        data_array[0].push("device.vap.@" + (i + 1));
        data_array[1].push(mcm_dv.device.vap[i].ekey);
        data_array[2].push(mcm_jslib_convert_html_str(mcm_dv.device.vap[i].ssid));
        data_array[3].push(mcm_dv.device.vap[i].channel);
    }
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    // 顯示 device.vap.*.extra
    data_array = new Array(3);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[0].push("");
    data_array[1].push("hidden");
    data_array[2].push("tx_power");
    for(i = 0; i < mcm_dv.device.vap.length; i++)
    {
        data_array[0].push("device.vap.@" + (i + 1) + ".extra");
        data_array[1].push(mcm_dv.device.vap[i].extra.hidden);
        data_array[2].push(mcm_dv.device.vap[i].extra.tx_power);
    }
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    // 顯示 device.vap.*.station.*
    data_array = new Array(4);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[3] = new Array();
    data_array[0].push("");
    data_array[1].push("ekey");
    data_array[2].push("mac_addr");
    data_array[3].push("rule");
    for(i = 0; i < mcm_dv.device.vap.length; i++)
        for(j = 0; j < mcm_dv.device.vap[i].station.length; j++)
        {
            data_array[0].push("device.vap.@" + (i + 1) + ".station.@" + (j + 1));
            data_array[1].push(mcm_dv.device.vap[i].station[j].ekey);
            data_array[2].push(
                mcm_jslib_convert_html_str(mcm_dv.device.vap[i].station[j].mac_addr));
            data_array[3].push(mcm_dv.device.vap[i].station[j].rule);
        }
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    // 顯示 device.limit.*
    data_array = new Array(4);
    data_array[0] = new Array();
    data_array[1] = new Array();
    data_array[2] = new Array();
    data_array[3] = new Array();
    data_array[0].push("");
    data_array[1].push("ekey");
    data_array[2].push("name");
    data_array[3].push("priority");
    for(i = 0; i < mcm_dv.device.limit.length; i++)
    {
        data_array[0].push("device.limit.@" + (i + 1));
        data_array[1].push(mcm_dv.device.limit[i].ekey);
        data_array[2].push(mcm_jslib_convert_html_str(mcm_dv.device.limit[i].name));
        data_array[3].push(mcm_dv.device.limit[i].priority);
    }
    tmp_html += jsapi_make_table("css_table1", "css_td1", data_array);

    $("#show_box").html(tmp_html);
}
</script>

</head>

<body onload="body_init()">

  <div id="show_box"></div>

</body>

</html>
